package xjtu.zd.server.user.myself.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xjtu.zd.server.common.CurrentUser;
import xjtu.zd.server.user.myself.BookDto;
import xjtu.zd.server.user.myself.RUserService;
import xjtu.zd.server.user.myself.WorkDto;
import xjtu.zd.server.user.myself.dao.myDao;
import xjtu.zd.server.user.myself.rUser;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class rUserServiceImpl implements RUserService {

    @Resource
    private myDao dao;

    @Override
    public rUser getNowUser(String id) {
        return dao.findNowUser(id);
    }

    @Override
    public List<BookDto> bookShelf(String id) {
        return dao.findBookShelf(id);
    }

    @Override
    public List<WorkDto> getWorks(String id) {
        return dao.findWorks(id);
    }
    @Override
    public void setAvatar(CurrentUser currentUser, String filename) {
        dao.updateAvatar(currentUser.getUserId(),filename);
    }
    @Override
    public boolean emailClash(String u_email) {
        int i = dao.ifemailClash(u_email);
        return i>0;
    }
    @Override
    public boolean nameClash(String u_name) {
        int i = dao.ifnameClash(u_name);
        return i>0;
    }
    @Override
    public void setNowUser(rUser user) {
        dao.updateUser(user);
    }
}
